// pages/classify/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    LeftFoodList:[],
    RightFoodList:[],
    idx:0,
    scrolltop:0,
    Chang:true,
    products:null,
    num:1, 
    active:true,
    num:1,
  } ,  
   
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      LeftFoodList:app.globalData.FoodList.map(v=>v.FoodList),//获取app中左侧分类列表数据
      RightFoodList:app.globalData.FoodList[0].children//获取app中右侧页面数据
    }) 
  },
  ShowBuy(e){//显示购买组件
    const products =e.currentTarget.dataset.products
    this.setData({
      products:products,
      Chang:false
    })
  },
  handItem(e){//切换显示列表对应数据
    const index =e.currentTarget.dataset.index
    this.setData({
     idx:index,
     RightFoodList:app.globalData.FoodList[index].children,
     scrolltop:0
    })
  },
  Act(){//切换选择规格
    this.setData({
      active:!this.data.active
    })
  },
  TurnTo(e){//跳转到食品页面
    const products=JSON.stringify(e.currentTarget.dataset.products)
    wx.navigateTo({
      url: '/pages/FoodsList/index?products='+products,
    })
  },
    Addshopping() {//添加当前用户点的商品到购物车
      let active = this.data.active
      let products = this.data.products
      let num = this.data.num
      app.cal(active,products,this,num,"Chang")
      this.setData({
        num:1,
      })
    },
    MathNum(e){//计算添加的数量
      let name = e.currentTarget.dataset.name
      let num = this.data.num
      let value = e.detail.value - 0 
      app.MathNum(name,num,this,value)
    },
    hid(){//切换显示
      this.setData({
        Chang:true
      })
    },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   
     
  },
})